﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class MyForm : Game
    {
        Font font = null;
        Brush blackBrush = null;
        Brush whiteBrush = null;

        public MyForm()
        {
            InitializeComponent();

            font = new Font("Simsun", 12);
            blackBrush = new SolidBrush(Color.Black);
            whiteBrush = new SolidBrush(Color.White);

            this.FPS = 100;
            //this.SuppressDraw();
        }

        int nData = 0;
        int nDrawCount = 0;
        int nUpdateCount = 0;

        protected override void Draw(GameTime gameTime)
        {
            nDrawCount++;
            int nDrawFPS = 1;
            int nUpdateFPS = 1;
            if (gameTime.TotalGameTime.Seconds > 0)
            {
                nDrawFPS = (int)(nDrawCount / gameTime.TotalGameTime.TotalSeconds);
                nUpdateFPS = (int)(nUpdateCount / gameTime.TotalGameTime.TotalSeconds);
            }
            string strFPS = string.Format(
                " DrawFPS {0} ,  UpdateFPS {1},  Data {2}", nDrawFPS, nUpdateFPS, nData);
            if (gameTime.IsRunningSlowly)
            {
                strFPS = strFPS + " IsRunningSlowly";
            }
            Graphics g = Graphics.FromHwnd(this.Handle);
            g.FillRectangle(whiteBrush, 10, 10, 500, 50);
            g.DrawString(strFPS, font, blackBrush, 10, 10);


            // 其中gameTime.ElapsedRealTime表示相邻两帧之间的时间间隔
            string strTime = string.Format("{0}s   {1}ms",
                gameTime.TotalGameTime.TotalSeconds, 
                gameTime.ElapsedRealTime.TotalMilliseconds);
            g.FillRectangle(whiteBrush, 10, 100, 400, 50);
            g.DrawString(strTime, font, blackBrush, 10, 100);
        }

        protected override void Update(GameTime gameTime)
        {
            nData++;
            nUpdateCount++;
        }
    }
}
